﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Moria
{
    public class MagicSpell
    {

        /* offsets to spell names in spell_names[] array */
        private const int SPELL_OFFSET = 0;
        private const int PRAYER_OFFSET = 31;

        static MagicSpell()
        {
            foreach (MagicSpell[] spellTable in MagicSpell.Table)
            {
                foreach (MagicSpell spell in spellTable)
                {
                    if (string.IsNullOrEmpty(spell.Name))
                    {
                        spell.Name = FindSpellName(spell);
                    }
                }
            }
        }

        private MagicSpell(string name, int level, int mana, int fail, int exp)
        {
            this.Name = name;
            this.slevel = level;
            this.smana = mana;
            this.sfail = fail;
            this.sexp = exp;
        }
        private static string FindSpellName(MagicSpell spell)
        {
            string[] spell_names = new string[]
           {
              /* Mage Spells */
              "Magic Missile",  "Detect Monsters",	"Phase Door",  "Light Area",
              "Cure Light Wounds",	"Find Hidden Traps/Doors",  "Stinking Cloud",
              "Confusion",	"Lightning Bolt",  "Trap/Door Destruction", "Sleep I",
              "Cure Poison",  "Teleport Self",  "Remove Curse",  "Frost Bolt",
              "Turn Stone to Mud",	"Create Food",	"Recharge Item I",  "Sleep II",
              "Polymorph Other",  "Identify",  "Sleep III",	 "Fire Bolt",  "Slow Monster",
              "Frost Ball",	 "Recharge Item II", "Teleport Other",	"Haste Self",
              "Fire Ball", "Word of Destruction", "Genocide",
              /* Priest Spells, start at index 31 */
              "Detect Evil",  "Cure Light Wounds",	"Bless",  "Remove Fear", "Call Light",
              "Find Traps",	 "Detect Doors/Stairs",	 "Slow Poison",	 "Blind Creature",
              "Portal",  "Cure Medium Wounds",  "Chant",  "Sanctuary",  "Create Food",
              "Remove Curse",  "Resist Heat and Cold",  "Neutralize Poison",
              "Orb of Draining",  "Cure Serious Wounds",  "Sense Invisible",
              "Protection from Evil",  "Earthquake",  "Sense Surroundings",
              "Cure Critical Wounds",  "Turn Undead",  "Prayer",  "Dispel Undead",
              "Heal",  "Dispel Evil",  "Glyph of Warding",	"Holy Word"
            };


            for (int count = 0; count < MagicSpell.Table.Length;count++ )
            {
                for (int ndx = 0; ndx < MagicSpell.Table[count].Length; ndx++)
                {
                    MagicSpell sp = MagicSpell.Table[count][ndx];
                    if (sp.slevel == spell.slevel && sp.smana == spell.smana &&
                        sp.sfail == spell.sfail && sp.sexp == spell.sexp)
                    {
                        if ( count == 1 || count ==4)                        return spell_names[ndx+PRAYER_OFFSET];
                        return spell_names[ndx];
                    }

                }
            }


            return string.Empty;

        }
        public string Name { get; private set; }
        public int slevel { get; private set; }
        public int smana { get; private set; }
        public int sfail { get; private set; }
        ///<summary>
        /// 1/4 of exp gained for learning spell 
        /// </summary>
        public int sexp { get; private set; }

        public static readonly MagicSpell[][] Table = new MagicSpell[][]
        {
            new MagicSpell[]
            {
            #region Mage
                new MagicSpell("",	1,  1, 22,   1),
                new MagicSpell("",	1,  1, 23,   1),
                new MagicSpell("",	1,  2, 24,   1),
                new MagicSpell("",	1,  2, 26,   1),
                new MagicSpell("",	3,  3, 25,   2),
                new MagicSpell("",	3,  3, 25,   1),
                new MagicSpell("",	3,  3, 27,   2),
                new MagicSpell("",	3,  4, 30,   1),
                new MagicSpell("",	5,  4, 30,   6),
                new MagicSpell("",	5,  5, 30,   8),
                new MagicSpell("",	5,  5, 30,   5),
                new MagicSpell("",	5,  5, 35,   6),
                new MagicSpell("",	7,  6, 35,   9),
                new MagicSpell("",	7,  6, 50,  10),
                new MagicSpell("",	7,  6, 40,  12),
                new MagicSpell("",	9,  7, 44,  19),
                new MagicSpell("",	9,  7, 45,  19),
                new MagicSpell("",	9,  7, 75,  22),
                new MagicSpell("",	9,  7, 45,  19),
                new MagicSpell("", 11,  7, 45,  25),
                new MagicSpell("", 11,  7, 99,  19),
                new MagicSpell("", 13,  7, 50,  22),
                new MagicSpell("", 15,  9, 50,  25),
                new MagicSpell("", 17,  9, 50,  31),
                new MagicSpell("", 19, 12, 55,  38),
                new MagicSpell("", 21, 12, 90,  44),
                new MagicSpell("", 23, 12, 60,  50),
                new MagicSpell("", 25, 12, 65,  63),
                new MagicSpell("", 29, 18, 65,  88),
                new MagicSpell("", 33, 21, 80, 125),
                new MagicSpell("", 37, 25, 95, 200) 
            #endregion
            },
            new MagicSpell[]
            {
            #region Priest
                new MagicSpell("",  1,  1, 10,   1),
                new MagicSpell("",  1,  2, 15,   1),
                new MagicSpell("",  1,  2, 20,   1),
                new MagicSpell("",  1,  2, 25,   1),
                new MagicSpell("",  3,  2, 25,   1),
                new MagicSpell("",  3,  3, 27,   2),
                new MagicSpell("",  3,  3, 27,   2),
                new MagicSpell("",  3,  3, 28,   3),
                new MagicSpell("",  5,  4, 29,   4),
                new MagicSpell("",  5,  4, 30,   5),
                new MagicSpell("",  5,  4, 32,   5),
                new MagicSpell("",  5,  5, 34,   5),
                new MagicSpell("",  7,  5, 36,   6),
                new MagicSpell("",  7,  5, 38,   7),
                new MagicSpell("",  7,  6, 38,   9),
                new MagicSpell("",  7,  7, 38,   9),
                new MagicSpell("",  9,  6, 38,  10),
                new MagicSpell("",  9,  7, 38,  10),
                new MagicSpell("",  9,  7, 40,  10),
                new MagicSpell("", 11,  8, 42,  10),
                new MagicSpell("", 11,  8, 42,  12),
                new MagicSpell("", 11,  9, 55,  15),
                new MagicSpell("", 13, 10, 45,  15),
                new MagicSpell("", 13, 11, 45,  16),
                new MagicSpell("", 15, 12, 50,  20),
                new MagicSpell("", 15, 14, 50,  22),
                new MagicSpell("", 17, 14, 55,  32),
                new MagicSpell("", 21, 16, 60,  38),
                new MagicSpell("", 25, 20, 70,  75),
                new MagicSpell("", 33, 24, 90, 125),
                new MagicSpell("", 39, 32, 99, 200)
     #endregion Priest
            },
            new MagicSpell[]
            {
            #region Rogue
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("",  5,  1, 50,   1),
                new MagicSpell("",  7,  2, 55,   1),
                new MagicSpell("",  9,  3, 60,   2),
                new MagicSpell("", 11,  4, 65,   2),
                new MagicSpell("", 13,  5, 70,   3),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 15,  6, 75,   3),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 17,  7, 80,   4),
                new MagicSpell("", 19,  8, 85,   5),
                new MagicSpell("", 21,  9, 90,   6),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 23, 10, 95,   7),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 25, 12, 95,   9),
                new MagicSpell("", 27, 15, 99,  11),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 29, 18, 99,  19),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
                new MagicSpell("", 99, 99,  0,   0),
            #endregion Rogue
            },
            new MagicSpell[]
            {
            #region Ranger
                new MagicSpell("",  3,  1, 30,   1),
                new MagicSpell("",  3,  2, 35,   2),
                new MagicSpell("",  3,  2, 35,   2),
                new MagicSpell("",  5,  3, 35,   2),
                new MagicSpell("",  5,  3, 40,   2),
                new MagicSpell("",  5,  4, 45,   3),
                new MagicSpell("",  7,  5, 40,   6),
                new MagicSpell("",  7,  6, 40,   5),
                new MagicSpell("",  9,  7, 40,   7),
                new MagicSpell("",  9,  8, 45,   8),
                new MagicSpell("", 11,  8, 40,  10),
                new MagicSpell("", 11,  9, 45,  10),
                new MagicSpell("", 13, 10, 45,  12),
                new MagicSpell("", 13, 11, 55,  13),
                new MagicSpell("", 15, 12, 50,  15),
                new MagicSpell("", 15, 13, 50,  15),
                new MagicSpell("", 17, 17, 55,  15),
                new MagicSpell("", 17, 17, 90,  17),
                new MagicSpell("", 21, 17, 55,  17),
                new MagicSpell("", 21, 19, 60,  18),
                new MagicSpell("", 23, 25, 95,  20),
                new MagicSpell("", 23, 20, 60,  20),
                new MagicSpell("", 25, 20, 60,  20),
                new MagicSpell("", 25, 21, 65,  20),
                new MagicSpell("", 27, 21, 65,  22),
                new MagicSpell("", 29, 23, 95,  23),
                new MagicSpell("", 31, 25, 70,  25),
                new MagicSpell("", 33, 25, 75,  38),
                new MagicSpell("", 35, 25, 80,  50),
                new MagicSpell("", 37, 30, 95, 100),
                new MagicSpell("", 99, 99,  0,   0)
            #endregion Ranger
            },            
            new MagicSpell[]
            {
            #region Paladin
                new MagicSpell("",  1,  1, 30,   1),
                new MagicSpell("",  2,  2, 35,   2),
                new MagicSpell("",  3,  3, 35,   3),
                new MagicSpell("",  5,  3, 35,   5),
                new MagicSpell("",  5,  4, 35,   5),
                new MagicSpell("",  7,  5, 40,   6),
                new MagicSpell("",  7,  5, 40,   6),
                new MagicSpell("",  9,  7, 40,   7),
                new MagicSpell("",  9,  7, 40,   8),
                new MagicSpell("",  9,  8, 40,   8),
                new MagicSpell("", 11,  9, 40,  10),
                new MagicSpell("", 11, 10, 45,  10),
                new MagicSpell("", 11, 10, 45,  10),
                new MagicSpell("", 13, 10, 45,  12),
                new MagicSpell("", 13, 11, 45,  13),
                new MagicSpell("", 15, 13, 45,  15),
                new MagicSpell("", 15, 15, 50,  15),
                new MagicSpell("", 17, 15, 50,  17),
                new MagicSpell("", 17, 15, 50,  18),
                new MagicSpell("", 19, 15, 50,  19),
                new MagicSpell("", 19, 15, 50,  19),
                new MagicSpell("", 21, 17, 50,  20),
                new MagicSpell("", 23, 17, 50,  20),
                new MagicSpell("", 25, 20, 50,  20),
                new MagicSpell("", 27, 21, 50,  22),
                new MagicSpell("", 29, 22, 50,  24),
                new MagicSpell("", 31, 24, 60,  25),
                new MagicSpell("", 33, 28, 60,  31),
                new MagicSpell("", 35, 32, 70,  38),
                new MagicSpell("", 37, 36, 90,  50),
                new MagicSpell("", 39, 38, 95, 100)
            #endregion Paladin
            }
        };
    }
}
